#region (c) 2009 Abdullin.com and Contributors

// Copyright (c) 2009 Abdullin.com and Contributors
// Site: http://abdullin.com/ncouch
// This code is released under the terms of the new BSD licence

#endregion

using System;
using NCouch.Error;
using NCouch.Rest;

namespace NCouch
{
	public sealed class CouchErrorSyntax
	{
		readonly IRestResponse _response;

		public CouchErrorSyntax(IRestResponse response)
		{
			_response = response;
		}

		internal CouchErrorSyntax On(CouchStatus status, Func<IRestResponse, Exception> func)
		{
			if (_response.StatusCode == (int) status)
				throw (func(_response));
			return this;
		}

		internal void Unless(CouchStatus status)
		{
			if (_response.StatusCode != (int) status)
				throw CouchError.Unexpected(_response);
		}
	}
}